package com.zrwl.poscloud.xo.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.entity.Employee;
import com.zrwl.poscloud.base.superI.SuperMapper;
import com.zrwl.poscloud.xo.vo.EmployeeVO;
import com.zrwl.poscloud.xo.vo.SubsidyDetailVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 持卡人员 Mapper类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-02-09
 */
public interface EmployeeMapper extends SuperMapper<Employee> {
    @Select("<script>" +
            " SELECT a.uid,a.name employeeName,a.cert_code certCode,a.sex,a.employee_code employeeCode,a.type,a.is_face_payment,b.uid deptUid,b.name deptName,b.company_uid,c.full_name companyFullName,substr(c.company_code,1,5)companyCode " +
            " FROM t_employee a LEFT JOIN t_dept b ON a.company_code=b.company_code LEFT JOIN t_company c ON b.company_uid=c.uid " +
            " WHERE b.company_uid=#{param.companyUid} AND a.status=1 AND b.status=1 " +
            " <if test='param.employeeName!=null and param.employeeName!=&quot;&quot;'>" +
            "  and a.name LIKE CONCAT('%',#{param.employeeName},'%')" +
            "  </if>" +
            " <if test='param.certCode!=null and param.certCode!=&quot;&quot;'>" +
            "  and a.cert_code LIKE CONCAT('%',#{param.certCode},'%')" +
            "  </if>" +
            " <if test='param.companyCode!=null and param.companyCode!=&quot;&quot;'>" +
            "  and a.company_code LIKE CONCAT(#{param.companyCode},'%')" +
            "  </if>" +
            " ORDER BY a.name ASC" +
            "</script>"
    )
    public IPage<EmployeeVO> mobileUserGetList(Page page, @Param("param") EmployeeVO employeeVO);

    @Select("<script>" +
            " SELECT a.uid,a.name employeeName,a.cert_code certCode,a.employee_code employeeCode,a.type,concat(c.short_name,'-',b.name) deptName " +
            " FROM t_employee a LEFT JOIN t_dept b ON a.company_code=b.company_code " +
            "  LEFT JOIN t_company c ON b.company_uid=c.uid " +
            " WHERE  a.status=1 AND b.status=1  AND c.status=1 " +
            " <if test='param.companyUid!=null and param.companyUid!=&quot;&quot;'>" +
            "  and c.uid = #{param.companyUid} " +
            " </if>" +
            " <if test='param.keyword!=null and param.keyword!=&quot;&quot;'>" +
            "  and (" +
            "   a.name like CONCAT('%',#{param.keyword},'%')" +
            "  or a.employee_code =#{param.keyword}" +
            "   or a.cert_code =#{param.keyword}" +
            "  )" +
            " </if>" +
            " ORDER BY a.create_Time DESC" +
            "</script>"
    )
    public IPage<EmployeeVO> getListForSelect(Page page, @Param("param") EmployeeVO employeeVO);

    public EmployeeVO getVerifyEmployeeVO(@Param("employeeVO") EmployeeVO employeeVO);

    public List<EmployeeVO> getTheFilteredEmployeeVO(@Param("subsidyDetailVO") SubsidyDetailVO subsidyDetailVO);

    int restoreAndLeaveTime(@Param("employeeVO") EmployeeVO employeeVO);

    public IPage<EmployeeVO> getPageList(Page page, @Param("param") EmployeeVO employeeVO);

    @Select("<script>" +
            " SELECT a.uid employeeUid,a.name,a.pay_level,a.status,a.daily_limit,a.monthly_limit,a.sync_code " +
            " FROM t_employee a " +
            " WHERE  a.status=1 AND SUBSTR(a.company_code,1,5)=(SELECT company_code FROM t_company WHERE uid=#{param.companyUid}) AND a.sync_code>#{param.presentFlowCode} " +
            " ORDER BY a.sync_code " +
            "</script>"
    )
    public IPage<EmployeeVO> getEmployeeListBySyncCode(Page page, @Param("param") EmployeeVO employeeVO);


    public int getEmployeeByDeptCode(@Param("code") String code);
    public List<EmployeeVO> getEmployeeMesByCodeAndNameOrCertCode(@Param("param") EmployeeVO employeeVO);

    @Select("<script>" +
            " select e.* " +
            " from t_employee e " +
            " where e.status = 1 " +
            "   <if test='param.deptRoleTree != null and param.deptRoleTree.length>0'> " +
            "     and e.company_code in  " +
            "     <foreach item='item' index='index' collection='param.deptRoleTree' open='(' separator=','  close=')'> " +
            "               #{item} " +
            "     </foreach> " +
            "   </if> " +
            " and (e.name = #{param.keyword} or e.employee_code = #{param.keyword} or e.cert_code = #{param.keyword} or e.uid = #{param.keyword}) " +
            "</script>"
    )
    public List<EmployeeVO> getEmployeeMesByCodeAndNameOrCertCodeNonCheck(@Param("param") EmployeeVO employeeVO);

    @Select("<script>" +
            " select" +
            " e.uid employeeUid,e.name employeeName, " +
            " e.cert_code certCode,e.employee_code employeeCode,e.company_code companyCode, " +
            " d.uid deptUid,d.name deptName,c.uid companyUid,c.full_name companyFullName,c.short_name companyName " +
            " from t_employee e left join t_dept d on e.company_code=d.company_code " +
            " left join t_company c on c.company_code=substr(d.company_code,1,5) " +
            " where e.uid = #{param.employeeUid} and e.status=1 and d.status=1 and c.status=1 " +
            "</script>"
    )
    public EmployeeVO getEmployeeDetailForMobile(@Param("param") EmployeeVO employeeVO);

    List<EmployeeVO> getAllListByCompany(@Param("param") EmployeeVO employeeVO);

    @Select("<script>" +
            "SELECT * FROM t_employee WHERE company_code LIKE CONCAT(#{companyCode},'%')" +
            "</script>"
    )
    List<Employee> getAllEmployeeListByCompanyCode(@Param("companyCode") String companyCode);

    Employee getEmployeeBySource(@Param("sourceType") int sourceType, @Param("userUid") String userUid, @Param("companyCode") String companyCode);
    List<EmployeeVO> getTeacherInfo(@Param("param") EmployeeVO employeeVO);

    IPage<EmployeeVO> getNameSakeList(@Param("page") Page page, @Param("param") EmployeeVO employeeVO);

    List<EmployeeVO> getGradeTeacherInfo(@Param("param") EmployeeVO employeeVO);
    List<EmployeeVO> getEmployeeListByDeptUid(@Param("deptUid") String deptUid);
    List<EmployeeVO> getTeacherMesByCodeAndNameOrCertCode(@Param("param") EmployeeVO employeeVO);

    EmployeeVO getEmployeeMesByCodeAndNameOrCertCodeAndSuffix(@Param("param") EmployeeVO employeeVO);
    List<EmployeeVO> getEmployeeAllListByGrade(@Param("gradeUid") String gradeUid);

    List<EmployeeVO> getGradeStudentInfo(@Param("param") EmployeeVO employeeVO);

    List<EmployeeVO> getAdminBindTeacherList(@Param("param") EmployeeVO employeeVO);

    List<EmployeeVO> getNoGradeTeacherMesByCodeAndNameOrCertCode(@Param("param") EmployeeVO employeeVO);

    EmployeeVO getEmployeeByUid(@Param("employeeUid") String employeeUid);
}
